package com.lx.boot.web.convert.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.lx.annotation.Note;
import com.lx.util.LX;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.IOException;

@AllArgsConstructor
public class SerializerPara {

    private JsonGenerator gen;

    private Object value;

    private Class filedType;

    @Note("通过反射get方法获取bean字段值")
    public Object getValue(){
        return value;
    }

    @Note("通过反射get方法获取bean的其他字段值")
    public Object getValue(String mapper){
        if (LX.isNotEmpty(mapper)){
            return LX.Reflection.getFieldValue(getObject(),mapper);
        }
        return value;
    }

    @Note("通过反射get方法获取bean的其他字段值")
    public <T>T getObject(){
        return (T) gen.getCurrentValue();
    }

    public JsonGenerator getJsonParser() {
        return gen;
    }

    public Class getFiledType(String mapper) {
        if (LX.isNotEmpty(mapper)){
            return LX.Reflection.getFieldType(gen.getCurrentValue(),mapper);
        }
        return filedType;
    }


}
